package com.songlanyun.modules.freighttemplate.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.modules.freighttemplate.model.dto.FreightTemplateDTO;
import com.songlanyun.modules.freighttemplate.model.vo.FreightSlim;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.freighttemplate.entity.FreightTemplate;
import com.songlanyun.modules.freighttemplate.service.FreightTemplateService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.user.controller.AbstractController;

/**
 * 商家的物流运费模板表
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-09 18:03:39
 */
@RestController
@RequestMapping("admin/freighttemplate")
public class FreightTemplateAdminController extends AbstractController {
    @Autowired
    private FreightTemplateService shopFreightTemplateService;

    /**
     * 添加物流运费模板
     */
    @SysLog("添加物流运费模板")
    @PostMapping("/add")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:save")
    public R add(@RequestBody FreightTemplateDTO dto){
        FreightTemplate obj = shopFreightTemplateService.add(getShopId(), dto);
        return R.ok().put("data",obj);
    }

    /**
     * 修改物流运费模板
     */
    @SysLog("修改物流运费模板")
    @PutMapping("/update")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:save")
    public R update(@RequestBody FreightTemplateDTO dto){
        FreightTemplate obj = shopFreightTemplateService.update(getShopId(), dto);
        return R.ok().put("data",obj);
    }

    /**
     * 设置物流运费模板为默认
     */
    @SysLog("设置物流运费模板为默认")
    @PutMapping("/default/{id}")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:save")
    public R setDefault(@PathVariable("id") Integer id){
        shopFreightTemplateService.setDefault(getShopId(),id);
        return R.ok();
    }



    /**
     * 商家所有的运费模板
     */
    @RequestMapping("/list")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:list")
    public R list(){
        List<FreightTemplate> all = shopFreightTemplateService.all(getShopId());
        return R.ok().put("list", all);
    }


    /**
     * 轻量级的
     * 商家所有的运费模板
     */
    @RequestMapping("/list-slim")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:list")
    public R listSlim(){
        List<FreightSlim> all = shopFreightTemplateService.slimList(getShopId());
        return R.ok().put("list", all);
    }

    /**
     * 按id查询一条模板
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:info")
    public R info(@PathVariable("id") Integer id){
		FreightTemplate shopFreightTemplate = shopFreightTemplateService.getFTemplateBy(getShopId(),id);
        return R.ok().put("data", shopFreightTemplate);
    }



    /**
     * 商家删除自己的运费模板
     */
    @SysLog("商家删除自己的运费模板")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:delete")
    public R delete(@PathVariable("id") Integer id){
        shopFreightTemplateService.delete(getShopId(),id);
        return R.ok();
    }


}
